package com.onpositive.dataminer.core.pmodel;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class AliasProvider {

	protected static HashMap<String, ArrayList<String>>aliases=new HashMap<String, ArrayList<String>>();
	
	static{
		try{
		InputStream resourceAsStream = AliasProvider.class.getResourceAsStream("pv.xml");
		Document parse = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resourceAsStream);
		NodeList elementsByTagName = parse.getDocumentElement().getElementsByTagName("takefrom");
		for (int a=0;a<elementsByTagName.getLength();a++){
			Element item = (Element) elementsByTagName.item(a);
			String attribute = item.getAttribute("from");
			String attribute2 = item.getAttribute("id");
			ArrayList<String> arrayList = aliases.get(attribute2);
			if (arrayList==null){
				arrayList=new ArrayList<String>();
				aliases.put(attribute2, arrayList);
			}
			arrayList.add(attribute);
		}
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public static String[] getPotentialInferenceRoutes(String propId){
		ArrayList<String> arrayList = aliases.get(propId);
		if (arrayList==null){
			return new String[0];
		}
		return arrayList.toArray(new String[arrayList.size()]);
	}
	
}
